package com.simpleim.starter.protoBuilder;

import com.simpleim.im.common.bean.User;
import com.simpleim.im.common.bean.msg.ProtoMsg;
import com.simpleim.starter.client.ClientSession;

public class LoginMsgBuilder extends BaseBuilder{

    private User user;

    private LoginMsgBuilder(User user, ClientSession session) {
        super(ProtoMsg.HeadType.LOGIN_REQUEST, session);
        this.user = user;
    }

    private ProtoMsg.Message build() {
        ProtoMsg.Message message = buildCommon(-1);
        ProtoMsg.LoginRequest.Builder loginBuilder = ProtoMsg.LoginRequest.newBuilder();
        loginBuilder.setToken(user.getToken())
                .setPlatform(user.getPlatform().ordinal())
                .setDeviceId(user.getDevId())
                .setUserId(user.getUid());
        return message.toBuilder()
                .setLoginRequest(loginBuilder.build())
                .setSessionId(getSession().getSessionId())
                .setType(getHeadType())
                .setSequence(getSeqId())
                .build();
    }



    public static ProtoMsg.Message buildLoginMsg(User user, ClientSession session) {
        LoginMsgBuilder msgBuilder = new LoginMsgBuilder(user, session);
        return msgBuilder.build();
    }

}
